package com.verisette.framework.basic.common.config;

import java.util.Map;

import org.apache.log4j.Logger;
import org.corp.agi.basic.common.util.LogFormatter;
import org.corp.agi.basic.persistence.dao.ConfigDAO;
import org.corp.agi.basic.persistence.domain.AgiMessage;
import org.corp.agi.common.bean.Message;
import org.corp.agi.common.config.MessageConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Required;

public class MessageConfigImpl implements MessageConfig{
	
	private static Logger logger = Logger.getLogger(MessageConfigImpl.class);	
	
	private ConfigDAO configDAO;
	@Autowired
	@Required
	public void setConfigDAO(@Qualifier("configDAO")ConfigDAO configDAO) {
		this.configDAO = configDAO;
	}
	
	public Message getMessage( String messageCode ){
		Map messageMap = configDAO.getMessageMap();
		AgiMessage message = (AgiMessage) messageMap.get(messageCode);
		if( message == null ){
			logger.error( LogFormatter.format("-", "-", LogFormatter.TYPE_CONFIG_ERROR, LogFormatter.OP_ENGINE, 
						  "Cannot find message : MessageCode = " + messageCode ) );
		}
		return message;
	}
}
